$(document).ready(function () {
	shcdjhcx.onLoad();
})

var shcdjhcx = (function () {
	var init = function () {
		//私有属性
		var curSeg;
		layui.use('form', function () {
			var form = layui.form
		});
		 $('#picCode').attr("src", 'http://jcpt.ha-n-tax.gov.cn/web/cm/showPictureCode.do?t=' + Math.random());
	}
	return {
		onLoad: function () {
			init();
			shcdjhcx.dateShow()
		},
		/*查询*/
		onQuery: function () {
			var name = $(".name").val();
			var cardId = $(".cardId").val();
			var timeStart = $("#startTime").val();
			var timeEnd = $("#endTime").val();
			var rcode = $(".rcode").val();
			if(name==null||name=='')
		    {
		    	 layer.msg("请输入姓名");
		    	 return false;
		    }
		    if(cardId==null||cardId=='')
		    {
		    	 layer.msg("请输入身份证号");
		    	 return false;
		    }
		   
			
			if(timeStart==null||timeStart=="")
			{
				 layer.msg("社保传递计划起不能为空");
		   	 	return false;
			}
			if(timeEnd==null||timeEnd=="")
			{
				 layer.msg("社保传递计划止不能为空");
		   	 	return false;
			}
			var sTime =new Date(timeStart.replace(/-/g,'/').replace(/T|Z/g,' ').trim());
			var eTime = new Date(timeEnd.replace(/-/g,'/').replace(/T|Z/g,' ').trim()); 
			var cha = parseInt(eTime.getTime()-sTime.getTime());
			if(cha/(1000*3600*24) > 31)
			{
				 layer.msg("起止日期不能超过一个月");
				return false;
			}
			if(rcode==null||rcode=='')
			{
			   	  layer.msg("请输入验证码");
			   	 return false;
			}
			$.ajax({
				url: "http://jcpt.ha-n-tax.gov.cn/web/platform/zcmgl/zcm/selectZrrsb.do",
				type: "GET",
				data: {
					NAME:name,
					CARDID:cardId,
					TIMESTART:timeStart,
					TIMEEND:timeEnd,
					rcode:rcode,
					CUR_USERID:"",
					START:'1',
					END:'7'
				
				},
				dataType: "jsonp",
				jsonpCallback: "shcdjhcx.onqueryCallback",
			});
			
		},
		onqueryCallback: function (jsonObj) {
			shcdjhcx.reloadPicCode()
            	switch (parseInt(jsonObj.code)) {
		                case 0:
		               	    if ( $.fn.dataTable.isDataTable( '#wxlShcdjhcx' ) ) {
			            		var table = $('#wxlShcdjhcx').DataTable();
			            		table.destroy();
			            	}
			            	$('#wxlShcdjhcx').removeAttr("width").DataTable({
			            		"data": jsonObj.data,
			            		"columns": [{
			            				"data": null,
			            				"render": function (data, type, full, meta) {
		                                    return meta.row + 1 + meta.settings._iDisplayStart;
		                                }
			            			},
			            			{
			            				"data": "SBJBJGMC"
			            			},
			            			{
			            				"data": "SBBM"
			            			},
			            			{
			            				"data": "NSRMC"
			            			},
			            			{
			            				"data": "SFZJLX_DM",
			            				"render":function(data){
			            					switch(data){
			            						case "201":
			            							return "身份证";
			            							break;
			            						default:
			            					}
			            				}
			            			},
			            			{
			            				"data": "SFZJHM"
			            			},
			            			{
			            				"data": "ZSXMMC"
			            			},
			            			{
			            				"data": "ZSPMMC"
			            			},
			            			{
			            				"data":"ZSZMMC"
			            			},
			            			{
			            				"data": "SKSSQQSTR"
			            			},
			            			{
			            				"data": "SKSSQZSTR"
			            			},
			            			{
			            				"data": "HDSCRQSTR"
			            			},
			            			{
			            				"data": "JSSJ"
			            			},
			            			{
			            				"data": "CLBZ",
			            				"render":function(data){
			            					switch(data){
			            						case "0":
			            							return "未处理";
			            							break;
			            						case "1":
			            							return "已处理";
			            							break;
			            						default:
			            					}
			            				}
			            			},
			            		],
			            		"ordering": false,
			            		"info": false,
			            		"lengthChange": false,
			            		"searching": false,
			            		'scrollX':   true
			            	});
			            	shcdjhcx.reloadPicCode();
		                    break;
		                default:
		                    layer.msg(jsonObj.msg);
		                    shcdjhcx.reloadPicCode();
		            }
            	
		},
		winReset: function () {
			$(".wxl_cxSearch input").val("");
			$("#wxlShcdjhcx tbody").empty()
		},
		/*日期显示*/
		dateShow:function(){
        	layui.use('laydate', function(){
			  var laydate = layui.laydate;
			  laydate.render({
				    elem: '#startTime'
				    ,theme: 'molv'
			 });
			  laydate.render({
				    elem: '#endTime'
				    ,theme: 'molv'
			 });
			})
       },
		//验证码
        reloadPicCode: function () {
            // http://jcpt.ha-n-tax.gov.cn
            $('#picCode').attr("src",'http://jcpt.ha-n-tax.gov.cn/web/cm/showPictureCode.do?t=' + Math.random());
        }

	}
})();
